package com.hctforgreen.greenservice.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import org.taptwo.android.widget.ViewFlow;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.TerminalCountDownExamDetailActivity;
import com.hctforgreen.greenservice.model.ExamSubEntity;
import com.hctforgreen.greenservice.utils.HctConstants;
import com.hctforgreen.greenservice.utils.KeyboardUtil;
import com.hctforgreen.greenservice.utils.Utils;

/**
 * 终端培训：考试答题|错题解析
 * *计算分数
 * @author DHB
 * 
 */
public class TerminalExamDetailChildListAdapter extends BaseAdapter {

	private ViewFlow mViewFlow;
	private Activity mActivity;
	private LayoutInflater mInflater;
	private List<ExamSubEntity> mEntities;
	private int mIndex = 0;

	/**
	 * 选择编号字典，将A~Z映射到0~25上
	 */
	private String[] mChoiceIndexLst = { "A", "B", "C", "D", "E", "F", "G",
			"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
			"U", "V", "W", "X", "Y", "Z" };
	/**
	 * 判断编号字典，将y~n映射到0~1上
	 */
	private String[] mTrueOrFalseIndexLst = { "A", "B" };
	private boolean bShowAnswerLayout = true;

	public int getmIndex() {
		return mIndex;
	}

	public void setmIndex(int mIndex) {
		this.mIndex = mIndex;
	}

	public List<ExamSubEntity> getmEntities() {
		return mEntities;
	}

	public TerminalExamDetailChildListAdapter(Activity activity, ViewFlow viewFlow,
			List<ExamSubEntity> entities, String sFrom) {
		mActivity = activity;
		mViewFlow = viewFlow;
		mEntities = entities;
		// mFrom = sFrom;
		mInflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public boolean isbShowAnswerLayout() {
		return bShowAnswerLayout;
	}

	public void setbShowAnswerLayout(boolean bShowAnswerLayout) {
		this.bShowAnswerLayout = bShowAnswerLayout;
	}

	@Override
	public int getCount() {
		return mEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return mEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		convertView = mInflater.inflate(R.layout.item_exam_detail_child_lst,
				null);

		final ExamSubEntity entity = (ExamSubEntity) getItem(position);
		/**
		 * 题目
		 */
		TextView subjectTv = (TextView) convertView
				.findViewById(R.id.tv_subject);
		subjectTv.setText((position + 1) + "/" + mEntities.size() + "   ."
				+ entity.name);

		// renderIndicRightTv(entity);
		updateChoiseLayout(convertView, entity);

		/**
		 * 答案解析
		 */
		TextView hintTv = (TextView) convertView.findViewById(R.id.tv_hint);
		hintTv.setText(mActivity.getString(R.string.hint_header)
				+ entity.analyze);
		/**
		 * 正确答案
		 */
		TextView answerTv = (TextView) convertView.findViewById(R.id.tv_answer);
		if (entity.answer.equals("y")) {
			answerTv.setText(mActivity.getString(R.string.answer_yes_hint));
		} else if (entity.answer.equals("n")) {
			answerTv.setText(mActivity.getString(R.string.answer_no_hint));
		} else {
			answerTv.setText(mActivity.getString(R.string.answer_header_hint)
					+ entity.answer);
		}

		ImageView imgStatus = (ImageView) convertView
				.findViewById(R.id.img_status);
		if (HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT
				.equals(entity.inputAnswerResult)) {
			imgStatus.setImageResource(R.drawable.ic_exam_result_right);
		} else {
			imgStatus.setImageResource(R.drawable.ic_exam_result_wrong);
		}

		LinearLayout answerLyt = (LinearLayout) convertView
				.findViewById(R.id.lyt_answer);
		if (bShowAnswerLayout) {
			answerLyt.setVisibility(View.VISIBLE);
		} else {
			answerLyt.setVisibility(View.GONE);
		}
		return convertView;
	}

	private void updateChoiseLayout(View convertView, final ExamSubEntity entity) {
		/**
		 * 单选
		 */
		RadioGroup singleRg = (RadioGroup) convertView
				.findViewById(R.id.rg_single_topic_selection);
		/**
		 * 多选
		 */
		LinearLayout multipleLyt = (LinearLayout) convertView
				.findViewById(R.id.lyt_multiple_choice);
		/**
		 * 判断
		 */
		RadioGroup trueOrFalseRg = (RadioGroup) convertView
				.findViewById(R.id.rg_true_or_false);
		/**
		 * 排序
		 */
		LinearLayout fillInTheBlanksLyt = (LinearLayout) convertView
				.findViewById(R.id.lyt_fill_in_the_blanks);

		entity.offerAnswerList = Answer2List(entity.option);
		entity.wrongAnswerList = Answer2List(entity.wrongAnswer);
		entity.rightAnswerList = Answer2List(entity.answer);
		/**
		 * 单选
		 */
		if (entity.type.equals("1")) {
			//Log.i("DATA", "是单选题");
			renderSingleChoiceLayout(convertView, entity, singleRg,
					multipleLyt, trueOrFalseRg, fillInTheBlanksLyt);

		}
		/**
		 * 多选
		 */
		else if (entity.type.equals("2")) {
			renderMultipleChoiceLayout(convertView, entity, singleRg,
					multipleLyt, trueOrFalseRg, fillInTheBlanksLyt);
		}
		/**
		 * 判断
		 */
		else if (entity.type.equals("3")) {
			renderTrueOrFalseLayout(convertView, entity, singleRg, multipleLyt,
					trueOrFalseRg, fillInTheBlanksLyt);
		}
		/**
		 * 排序
		 */
		else if (entity.type.equals("4")) {
			renderFillInTheBlanksLayout(convertView, entity, singleRg,
					multipleLyt, trueOrFalseRg, fillInTheBlanksLyt);
		} else {//

		}
	}

	/**
	 * FIXME 计算单选题分数
	 */
	private void scoreSingleChoice(final ExamSubEntity entity) {
		if (mActivity instanceof TerminalCountDownExamDetailActivity) {
			if (entity.inputAnswer.equals(entity.answer)) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT;
				entity.inputAnswerScore = Double.valueOf(entity.point);
				//Log.i("DATA", "单选题  选择答案后"+entity.point);
				//Log.i("DATA", "单选题  选择答案后"+entity.inputAnswerScore);
			} else if (!entity.inputAnswer.equals(entity.answer)) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG;
				entity.inputAnswerScore = Double.valueOf(0);
			}
		}
	}

	/**
	 * FIXME 计算多选题分数
	 * 
	 * @param entity
	 */
	private void scoreMultipleChoice(final ExamSubEntity entity) {
		if (mActivity instanceof TerminalCountDownExamDetailActivity) {
			boolean isHalfRight = false;
			boolean hasEmpty = false;
			boolean hasWrong = false;
			for (String sRightAnswer : entity.rightAnswerList) {
				if (entity.inputAnswerList.contains(sRightAnswer)) {
					isHalfRight = true;
					for (String sInputAnswer : entity.inputAnswerList) {
						if (!entity.rightAnswerList.contains(sInputAnswer)) {
							hasWrong = true;
						}
					}

				} else if (!entity.inputAnswerList.contains(sRightAnswer)) {
					hasEmpty = true;
				}

			}
			if (!isHalfRight) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG;
				entity.inputAnswerScore = Double.valueOf(0);
			} else if (isHalfRight && !hasEmpty && !hasWrong) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT;
				entity.inputAnswerScore = Double.valueOf(entity.point);
			} else if (isHalfRight && hasEmpty && !hasWrong) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_HALF_RIGHT;
				entity.inputAnswerScore = Double.valueOf(entity.point) / 2;
			} else if (isHalfRight && hasWrong) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG;
				entity.inputAnswerScore = Double.valueOf(0);
			}
		}
	}

	/**
	 * FIXME 计算判断题分数
	 * 
	 * @param entity
	 */
	private void scoreTrueOrFalseChoice(final ExamSubEntity entity) {
		if (mActivity instanceof TerminalCountDownExamDetailActivity) {
			if (entity.inputAnswer.equals(entity.answer)) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT;
				entity.inputAnswerScore = Double.valueOf(entity.point);
			} else if (!entity.inputAnswer.equals(entity.answer)) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG;
				entity.inputAnswerScore = Double.valueOf(0);
			}
		}
	}

	/**
	 * FIXME 计算排序题分数
	 * 
	 * @param entity
	 */
	private void scoreFillInTheBlanksChoice(final ExamSubEntity entity) {
		if (entity.inputAnswer == null) {
			return;
		}
		if (mActivity instanceof TerminalCountDownExamDetailActivity) {

			if (!entity.inputAnswer.equalsIgnoreCase(entity.answer)) {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_WRONG;
				entity.inputAnswerScore = Double.valueOf(0);
			} else {
				entity.inputAnswerResult = HctConstants.INPUT_ANSWER_RESULT_ALL_RIGHT;
				entity.inputAnswerScore = Double.valueOf(entity.point);
			}
		}
	}

	private void initInputAnswerList(final ExamSubEntity entity,
			final int answerNum) {
		if (entity.inputAnswerList == null) {
			entity.inputAnswerList = new ArrayList<String>();
			if (answerNum != 0) {
				for (int i = 0; i < answerNum; i++) {
					entity.inputAnswerList.add("");
				}
			}
		}

	}

	/**
	 * 渲染单选
	 * 
	 * @param convertView
	 * @param entity
	 * @param singleRg
	 * @param multipleLyt
	 * @param trueOrFalseRg
	 * @param fillInTheBlanksLyt
	 */
	private void renderSingleChoiceLayout(View convertView,
			final ExamSubEntity entity, RadioGroup singleRg,
			LinearLayout multipleLyt, RadioGroup trueOrFalseRg,
			LinearLayout fillInTheBlanksLyt) {
		singleRg.setVisibility(View.VISIBLE);
		multipleLyt.setVisibility(View.GONE);
		trueOrFalseRg.setVisibility(View.GONE);
		fillInTheBlanksLyt.setVisibility(View.GONE);

		RadioGroup group = (RadioGroup) convertView
				.findViewById(R.id.rg_single_topic_selection);
		group.removeAllViews();
		for (int i = 0; i < entity.offerAnswerList.size(); i++) {
			final RadioButton choiceRb = (RadioButton) mActivity
					.getLayoutInflater().inflate(
							R.layout.rb_single_choice_layout, null);
			android.widget.LinearLayout.LayoutParams params = new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
			choiceRb.setLayoutParams(params);

			String sChoice = entity.offerAnswerList.get(i);
			choiceRb.setId(i);
			choiceRb.setText(sChoice);

			renderInputSingleChoice(entity, i, choiceRb);
			
			saveInputSingleChoice(entity, i, choiceRb);
			//Log.i("DATA", "单选题  保存后"+entity.inputAnswerScore);
			renderWroSingleChoice(entity, i, choiceRb);
			if (bShowAnswerLayout) {
				choiceRb.setClickable(false);
			}
			group.addView(choiceRb, i);
		}
	}

	/**
	 * 开始计算，并保存单选题分数
	 * 
	 * @param entity
	 * @param i
	 * @param choiceRb
	 */
	private void saveInputSingleChoice(final ExamSubEntity entity, final int i,
			final RadioButton choiceRb) {
		choiceRb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (choiceRb.isChecked()) {
					entity.inputAnswer = mChoiceIndexLst[i];
				} else {
					entity.inputAnswer = "";
				}
				scoreSingleChoice(entity);

			}
		});
	}

	private void renderInputSingleChoice(final ExamSubEntity entity, int i,
			RadioButton choiceRb) {
		// if
		// (mFrom.equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_TEST_ACTIVITY)
		// ||
		// mFrom.equals(HctConstants.ON_ACTIVITY_FROM_RANDOM_EXAMS_TEST_ACTIVITY)
		// ||
		// mFrom.equals(HctConstants.ON_ACTIVITY_FROM_SIMULATION_EXAMS_TEST_ACTIVITY)
		// || mFrom.equals(HctConstants.ON_ACTIVITY_FROM_TEST_CENTER_ACTIVITY)
		// ||
		// mFrom.equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_DETAIL_ACTIVITY))
		// {

		if (i < mChoiceIndexLst.length) {
			if (entity.inputAnswer.equals(mChoiceIndexLst[i])) {
				choiceRb.setChecked(true);
				scoreSingleChoice(entity);
			}
		}
		// choiceRb.setClickable(false);
		// }
	}

	private void renderWroSingleChoice(final ExamSubEntity entity, int i,
			RadioButton choiceRb) {
		// if (mFrom
		// .equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_FOLDER_ACTIVITY)
		// ||
		// mFrom.equals(HctConstants.ON_ACTIVITY_FROM_COLLECTION_FOLDER_ACTIVITY)
		// ||
		// mFrom.equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_DETAIL_ACTIVITY))
		// {
		// choiceRb.setButtonDrawable(R.drawable.rb_default_wrong_btn);
		// if (!mFrom
		// .equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_DETAIL_ACTIVITY)) {
		if (i < mChoiceIndexLst.length) {
			if (entity.wrongAnswer.equals(mChoiceIndexLst[i])) {
				choiceRb.setChecked(true);
			}
		}
		// choiceRb.setClickable(false);
		// } else if (mFrom
		// .equals(HctConstants.ON_ACTIVITY_FROM_WRO_EXAMS_DETAIL_ACTIVITY)) {
		// choiceRb.setClickable(false);
		// }

	}

	/**
	 * 渲染多选
	 * 
	 * @param convertView
	 * @param entity
	 * @param singleRg
	 * @param multipleLyt
	 * @param trueOrFalseRg
	 * @param fillInTheBlanksLyt
	 */
	private void renderMultipleChoiceLayout(View convertView,
			final ExamSubEntity entity, RadioGroup singleRg,
			LinearLayout multipleLyt, RadioGroup trueOrFalseRg,
			LinearLayout fillInTheBlanksLyt) {
		initInputAnswerList(entity, 0);
		singleRg.setVisibility(View.GONE);
		multipleLyt.setVisibility(View.VISIBLE);
		trueOrFalseRg.setVisibility(View.GONE);
		fillInTheBlanksLyt.setVisibility(View.GONE);

		LinearLayout group = (LinearLayout) convertView
				.findViewById(R.id.lyt_multiple_choice);
		group.removeAllViews();
		for (int i = 0; i < entity.offerAnswerList.size(); i++) {
			CheckBox choiceCb = (CheckBox) mActivity.getLayoutInflater()
					.inflate(R.layout.cb_multiple_choice_layout, null);
			android.widget.LinearLayout.LayoutParams params = new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
			params.setMargins(0, 10, 0, 10);
			choiceCb.setLayoutParams(params);
			String sChoice = entity.offerAnswerList.get(i);
			choiceCb.setId(i);
			choiceCb.setText(sChoice);

			renderInputMultipleChoice(entity, i, choiceCb);
			saveInputMultipleChoice(entity, i, choiceCb);
			renderWroMultipleChoice(entity, i, choiceCb);
			if (bShowAnswerLayout) {
				choiceCb.setClickable(false);
			}
			group.addView(choiceCb, i);
		}
	}

	private void saveInputMultipleChoice(final ExamSubEntity entity,
			final int i, final CheckBox choiceCb) {
		choiceCb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (choiceCb.isChecked()) {
					entity.inputAnswerList.add(mChoiceIndexLst[i]);
				} else {
					entity.inputAnswerList.remove(mChoiceIndexLst[i]);
				}
				scoreMultipleChoice(entity);
			}
		});
	}

	private void renderInputMultipleChoice(final ExamSubEntity entity, int i,
			CheckBox choiceCb) {

		if (i < mChoiceIndexLst.length) {
			for (int j = 0; j < entity.inputAnswerList.size(); j++) {
				if (entity.inputAnswerList.get(j).equals(mChoiceIndexLst[i])) {
					choiceCb.setChecked(true);
				}
			}
			scoreMultipleChoice(entity);
		}
	}

	private void renderWroMultipleChoice(final ExamSubEntity entity, int i,
			CheckBox choiceCb) {
		// choiceCb.setButtonDrawable(R.drawable.rb_default_wrong_btn);
		if (i < mChoiceIndexLst.length) {
			for (int j = 0; j < entity.wrongAnswerList.size(); j++) {
				if (entity.wrongAnswerList.get(j).equals(mChoiceIndexLst[i])) {
					choiceCb.setChecked(true);
				}
			}
		}
	}

	/**
	 * 渲染判断
	 * 
	 * @param convertView
	 * @param singleRg
	 * @param multipleLyt
	 * @param trueOrFalseRg
	 * @param fillInTheBlanksLyt
	 */
	private void renderTrueOrFalseLayout(View convertView,
			final ExamSubEntity entity, RadioGroup singleRg,
			LinearLayout multipleLyt, RadioGroup trueOrFalseRg,
			LinearLayout fillInTheBlanksLyt) {
		singleRg.setVisibility(View.GONE);
		multipleLyt.setVisibility(View.GONE);
		trueOrFalseRg.setVisibility(View.VISIBLE);
		fillInTheBlanksLyt.setVisibility(View.GONE);

		RadioGroup group = (RadioGroup) convertView
				.findViewById(R.id.rg_true_or_false);
		group.removeAllViews();
		for (int i = 0; i < 2; i++) {
			RadioButton choiceRb = (RadioButton) mActivity.getLayoutInflater()
					.inflate(R.layout.rb_true_or_false_layout, null);
			android.widget.LinearLayout.LayoutParams params = new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
			choiceRb.setLayoutParams(params);

			String sChoice = entity.offerAnswerList.get(i);
			// if (i == 0) {
			// sChoice = mActivity.getString(R.string.answer_yes_hint);
			// } else if (i == 1) {
			// sChoice = mActivity.getString(R.string.answer_no_hint);
			// }
			choiceRb.setId(i);
			choiceRb.setText(sChoice);
			renderInputTrueOrFalseChoice(entity, i, choiceRb);
			saveInputTrueOrFalseChoice(entity, i, choiceRb);
			renderWroTrueOrFalseChoice(entity, i, choiceRb);
			if (bShowAnswerLayout) {
				choiceRb.setClickable(false);
			}
			group.addView(choiceRb, i);
		}
	}

	private void renderInputTrueOrFalseChoice(final ExamSubEntity entity,
			int i, RadioButton choiceRb) {

		if (i < mTrueOrFalseIndexLst.length) {
			if (entity.inputAnswer.equals(mTrueOrFalseIndexLst[i])) {
				choiceRb.setChecked(true);
				scoreTrueOrFalseChoice(entity);
			}
		}
	}

	private void saveInputTrueOrFalseChoice(final ExamSubEntity entity,
			final int i, final RadioButton choiceRb) {
		choiceRb.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (choiceRb.isChecked()) {
					entity.inputAnswer = mTrueOrFalseIndexLst[i];
				} else {
					entity.inputAnswer = "";
				}
				scoreTrueOrFalseChoice(entity);

			}
		});
	}

	private void renderWroTrueOrFalseChoice(final ExamSubEntity entity, int i,
			RadioButton choiceRb) {
		if (i < mTrueOrFalseIndexLst.length) {
			if (entity.wrongAnswer.equals(mTrueOrFalseIndexLst[i])) {
				choiceRb.setChecked(true);
			}
		}
	}

	/**
	 * 渲染排序题
	 * 
	 * @param convertView
	 * @param entity
	 * @param singleRg
	 * @param multipleLyt
	 * @param trueOrFalseRg
	 * @param fillInTheBlanksLyt
	 */
	private void renderFillInTheBlanksLayout(View convertView,
			final ExamSubEntity entity, RadioGroup singleRg,
			LinearLayout multipleLyt, RadioGroup trueOrFalseRg,
			LinearLayout fillInTheBlanksLyt) {

		singleRg.setVisibility(View.GONE);
		multipleLyt.setVisibility(View.GONE);
		trueOrFalseRg.setVisibility(View.GONE);
		fillInTheBlanksLyt.setVisibility(View.VISIBLE);
		LinearLayout group = (LinearLayout) convertView
				.findViewById(R.id.lyt_fill_in_the_blanks);
		group.removeAllViews();
		// initInputAnswerList(entity, answerNum);/
		for (int i = 0; i < entity.offerAnswerList.size(); i++) {
			LinearLayout choiceLyt = (LinearLayout) mActivity
					.getLayoutInflater().inflate(
							R.layout.lyt_answer_item_layout, null);
			android.widget.LinearLayout.LayoutParams params = new LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

			choiceLyt.setLayoutParams(params);

			String sChoice = entity.offerAnswerList.get(i);
			choiceLyt.setId(i);
			TextView numberTv = (TextView) choiceLyt
					.findViewById(R.id.tv_number);
			numberTv.setText(sChoice);
			group.addView(choiceLyt, i);
		}
		LinearLayout inputLyt = (LinearLayout) mActivity.getLayoutInflater()
				.inflate(R.layout.lyt_answer_input_layout, null);
		android.widget.LinearLayout.LayoutParams params = new LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		params.setMargins(0, Utils.pxToDip(40, mActivity), 0,
				Utils.pxToDip(20, mActivity));
		inputLyt.setLayoutParams(params);

		EditText contentEt = (EditText) inputLyt
				.findViewById(R.id.et_answer_input);
		renderInputFillInTheBlanksChoice(entity, 0, contentEt);
		saveInputFillInTheBlanksChoice(entity, 0, contentEt);
		renderWroFillInTheBlanksChoice(entity, 0, contentEt);
		if (bShowAnswerLayout) {
			contentEt.setEnabled(false);
		}
		group.addView(inputLyt, params);
	}

	private void saveInputFillInTheBlanksChoice(final ExamSubEntity entity,
			final int i, final EditText contentEt) {
		contentEt.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				entity.inputAnswer = contentEt.getText().toString();
				if (entity.inputAnswerList != null
						&& i < entity.inputAnswerList.size()) {
					entity.inputAnswerList.set(i, contentEt.getText()
							.toString());
				}
				scoreFillInTheBlanksChoice(entity);

			}
		});

	}

	private void renderInputFillInTheBlanksChoice(final ExamSubEntity entity,
			int i, EditText contentEt) {
		// if(!entity.inputAnswer.equals("0")){
		if (entity.inputAnswer != null) {
			contentEt.setText(entity.inputAnswer);
		}
		// }
	}

	private void renderWroFillInTheBlanksChoice(final ExamSubEntity entity,
			int i, EditText contentEt) {

		// contentEt.setFocusable(false);
		// contentEt.setFocusableInTouchMode(false);
		// contentEt.setBackgroundResource(R.drawable.ic_wro_answer_input_bg);
		// if(!entity.wrongAnswer.equals("0")){
		// if (i < entity.wrongAnswerList.size()) {
		// contentEt.setText(entity.wrongAnswerList.get(0));
		// }
		// }

	}

	private static List<String> Answer2List(String Answer) {
		String[] arrAnswer = Answer.split(";");
		List<String> list = new ArrayList<String>();
		if (arrAnswer != null && arrAnswer.length > 0) {
			for (int i = 0; i < arrAnswer.length; i++) {
				list.add(arrAnswer[i]);
			}

		}
		return list;
	}

}
